package com.example.easyscript.service.task;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.easyscript.common.minio.MinioUtil;
import com.example.easyscript.entity.task.Image;
import com.example.easyscript.mapper.ImageMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

/**
 * @author huzixian
 * @date 2023-03-08
 */
@Slf4j
@Service
public class ImageService extends ServiceImpl<ImageMapper, Image> {

    @Resource
    MinioUtil minioUtil;

    public List<String> getImageUrlListByIds(List<Integer> imageIds) {
        return baseMapper.getImageUrlListByIds(imageIds);
    }

    public String getUrlByImageId(Integer imageId) {
        return baseMapper.getgetUrlByImageId(imageId);
    }

    public List<Image> getImageList(List<Integer> imageIds) {
        if (imageIds == null || imageIds.size() == 0) {
            return Collections.EMPTY_LIST;
        }
        List<Image> imageList = this.listByIds(imageIds);
        imageList.stream().forEach(item -> {
            item.setImageUrl(minioUtil.fileUrl(item.getImageUrl()));
        });
        return imageList;
    }
}
